/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gr.anagnosg.general.utils;

import java.io.File;
import java.util.HashMap;

/**
 *
 * @author anagnosg
 */
public class Ocr {
    public static HashMap recognize(File files[],String args){
        
        //String command = "tesseract"
        HashMap hm = new HashMap();
        File fnArray[] = new File[files.length];
        for(int i= 0 ; i < files.length; i++){
            File ft = files[i];
            String pathPrefix=ft.getParent()+File.separatorChar;
            String fn =FileUtils.getFilenameNoExt(ft);
            String commandConvert = "tesseract "+pathPrefix+ft.getName()+" "+pathPrefix+fn+""+args;
            System.out.println(commandConvert);
            String output = ExtrernalUtils.executeCommand(commandConvert);
            File filn = new File(pathPrefix+fn+".txt");
            fnArray[i]=filn;
        }
        hm.put("files", fnArray);
        return hm;
    }
    
    public static HashMap createBoxFile(File files[],String args){
        HashMap hm =new HashMap();
        File fnArray[] = new File[files.length];
        for(int i=0; i< files.length;i++){
            File ft = files[i];
            String pathPrefix = ft.getParent()+File.separatorChar;
            String fn =FileUtils.getFilenameNoExt(ft);
            createBoxSFile(ft.getAbsolutePath(),pathPrefix+fn+".box","ell");
            fnArray[i]=new File(pathPrefix+fn+".box");
        }
        return hm;
    }
    public static void createBoxSFile(String filename, String outputfile, String lang){
        String cmd = "tesseract "+filename+" "+outputfile+" -l "+lang+"  batch.nochop makebox";
        //tesseract s1_p0.tif ell.verdana.exp0 -l ell    batch.nochop makebox
        String output = ExtrernalUtils.executeCommand(cmd);
    }
}
